﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                fillName();
            }
        }

        public DataSet Connect(string query)
        {
            SqlConnection sqlCOn = new SqlConnection();
            sqlCOn.ConnectionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=NTest;Integrated Security=True";
            sqlCOn.Open();

            SqlCommand SQLCOMM = new SqlCommand();
            SQLCOMM.Connection = sqlCOn;

            SQLCOMM.CommandText = query;
            SQLCOMM.CommandType = CommandType.Text;

            DataSet ds = new DataSet();
            SqlDataAdapter SQLAD = new SqlDataAdapter(SQLCOMM);
            SQLAD.Fill(ds);

            sqlCOn.Close();
            return ds;      
        }


        public void fillName()
        {
            string q = "select * from TBLTEST";
            GridView1.DataSource = Connect(q);
            GridView1.DataBind();
        }

    }
}